args Controls outcomes lab keep ipw CreativityMeasure a1 a2 a3 a4 a5 a6 a7 a8

preserve


replace Creativity=creativityt_`CreativityMeasure'_7


* All estimations
foreach o of local outcomes {

	if `ipw'==1{
		ge io=`o'!=.
		qui logit io $HDC_0
		drop io
		predict p, pr
		su p
	}

	if `ipw'==0{
		ge p=1
	}

	qui rifhdreg `o' `Controls' [pweight=1/p], rif(mean) rob
	drop p

	est sto es_`o'
	mat b = e(b)
	mat b = b'
	svmat b
	qui su b1 if b1!=0
	mat define p= r(N)
	drop b1
	qui estadd scalar Par=p[1,1]
	local x ""
	qui estadd local x
}

* count number of varibles
local count: word count `outcomes'
local count=`count'+1
local text  "prehead( \\ ) prefoot( \cline{2-`count'}  \vspace{-.3cm}\\ ) postfoot(\vspace{-.4cm}  \\ )  posthead(\cline{2-`count'})"

* Stats
local stR "stats(N rifmean,     fmt(%11.0gc %8.2f)          labels("Number of individuals"  "Mean dep. var." ))"

* Results table
esttab es* using results/Tables/R_OLS_`lab'.tex, ///
	replace `text' se star(* 0.1 ** 0.05 *** 0.01) b(%9.3f) se(%9.3f) nonumbers collabels(none) ///
	keep(Creativity `keep') refcat(Creativity ""  " " "", nolabel) ///
	order(Creativity) varlabels(Creativity Creativity CogAbility "Cognitive ability"  "generalab_sd_11" "Cognitive ability") ///
	cells(b(star fmt(3)) se(par) ".") nogaps   alignment(c) ///
	mtitles("`a1'" "`a2'" "`a3'" "`a4'" "`a5'" "`a6'" "`a7'" "`a8'") frag `stR'

esttab es* using results/Tables/R_OLS_`lab'p.tex, ///
	replace `text' se star(* 0.1 ** 0.05 *** 0.01) b(%9.3f) se(%9.3f) nonumbers collabels(none) ///
	keep(Creativity `keep') refcat(Creativity ""  " " "", nolabel) ///
	order(Creativity) varlabels(Creativity Creativity CogAbility "Cognitive ability"  "generalab_sd_11" "Cognitive ability") ///
	cells(b(star fmt(3)) se(par) p(par([ ]) fmt(%9.5f)) ".") nogaps   alignment(c) ///
	mtitles("`a1'" "`a2'" "`a3'" "`a4'" "`a5'" "`a6'" "`a7'" "`a8'") frag `stR'


est drop _all
restore

